package shujia.day08;

/*
    添加功能
        public StringBuffer append(String str)
        public StringBuffer insert(int offset,String str)
    删除功能
        public StringBuffer deleteCharAt(int index)
        public StringBuffer delete(int start,int end)
    替换功能
        public StringBuffer replace(int start,int end,String str)
    反转功能
        public StringBuffer reverse()
    截取功能
        public String substring(int start)
        public String substring(int start,int end)


 */
public class StringBufferDemo2 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();

        //public StringBuffer append(String str) 末尾处追加
        sb.append(10);
        sb.append(12.34);
        sb.append(true);
        sb.append("hello");
        sb.append('w');
        System.out.println("sb: "+sb);

        //1012.34truehellow
        //public StringBuffer insert(int offset,String str) 指定索引插入元素
        sb.insert(5,"java");
        System.out.println("sb: "+sb);

        //1012.java34truehellow
        //public StringBuffer deleteCharAt(int index) 根据索引删除元素
        sb.deleteCharAt(7);
        System.out.println("sb: "+sb);

        //1012.jaa34truehellow
        //public StringBuffer delete(int start,int end) 指定开始和结束索引删除一部分字符
        sb.delete(7,11);
        System.out.println("sb: "+sb);

        //1012.jaruehellow
        //public StringBuffer replace(int start,int end,String str)  替换StringBuffer一部分字符序列
        sb.replace(7,10,"flink");
        System.out.println("sb: "+sb);

        //public StringBuffer reverse() 将StringBuffer中的字符序列反转
        StringBuffer sb2 = new StringBuffer("hello");
        sb2.reverse();
        System.out.println("sb2: "+sb2);


        //public String substring(int start)
        StringBuffer sb3 = new StringBuffer("世界很大，我想去看看！");
        String s1 = sb3.substring(5);
        System.out.println("sb3: "+sb3);
        System.out.println("s1: "+s1);

        String s2 = sb3.substring(5,8);
        System.out.println("sb3: "+sb3);
        System.out.println("s1: "+s2);

    }
}
